
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        12/25/2008
 * PROJECT:             MCWEBSITE
 * PURPOSE:             websiteStaticContentDAL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Web.Configuration;
using MCWEBSITE.ENTITY;

namespace MCWEBSITE.DAL
{
    public class websiteStaticContentDAL
    {
        #region  Properties
		 
		public static string FIELD_SATATICCONTENTID = "SataticContentID";  
		public static string FIELD_LANGUAGECODE = "LanguageCode";  
		public static string FIELD_STATICCONTENTCODE = "StaticContentCode";  
		public static string FIELD_STATICCONTENT = "StaticContent";  
		public static string FIELD_DESCRIPTION = "Description";  
		public static string FIELD_ATRIBUTE1 = "Atribute1";  
		public static string FIELD_ATRIBUTE2 = "Atribute2";  
		public static string FIELD_ATRIBUTE3 = "Atribute3"; 
		public static string ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ContentConnectionString"].ToString();

        #endregion

        #region Protected methods

        /// <summary>
        /// Select entity of websiteStaticContent
        /// </summary>
        /// <param name="SataticContentID">Primary Keys</param>
        /// <returns>Collection of websiteStaticContentInfo</returns>
        public static websiteStaticContentInfo SelectOne(int SataticContentID)
        {
            websiteStaticContentInfo _websiteStaticContentInfo = new websiteStaticContentInfo();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteStaticContentSelectOne", SataticContentID);
                if (dr.Read())
                    setwebsiteStaticContentInfo(dr, ref _websiteStaticContentInfo);
                return _websiteStaticContentInfo;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dr.Close();
            }
        }

        public static websiteStaticContentInfo SelectByCode(string SataticContentCode)
        {
            websiteStaticContentInfo _websiteStaticContentInfo = new websiteStaticContentInfo();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteStaticContentSelectByCode", SataticContentCode);
                if (dr.Read())
                    setwebsiteStaticContentInfo(dr, ref _websiteStaticContentInfo);
                return _websiteStaticContentInfo;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dr.Close();
            }
        }

        public static websiteStaticContentInfo SelectByLanguageAndCode(string Language,string StaticCode)
        {
            websiteStaticContentInfo _websiteStaticContentInfo = new websiteStaticContentInfo();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteStaticContentSelectByLanguageAndCode", Language, StaticCode);
                if (dr.Read())
                    setwebsiteStaticContentInfo(dr, ref _websiteStaticContentInfo);
                return _websiteStaticContentInfo;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select all websiteStaticContent
        /// </summary>
        /// <returns>Collection of websiteStaticContentInfo</returns>
        public static List<websiteStaticContentInfo> SelectAll()
        {
            List<websiteStaticContentInfo> lstwebsiteStaticContent = new List<websiteStaticContentInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteStaticContentSelectAll");
                setListwebsiteStaticContentInfo(ref dr, ref lstwebsiteStaticContent);
                return lstwebsiteStaticContent;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select
        /// </summary>
        /// <param name="websiteStaticContentnfo">Modify this method adapting your need</param>
        /// <returns>Collection of websiteStaticContentInfo</returns>
        public static List<websiteStaticContentInfo> SelectFilters()
        {
            string criterias = string.Empty;
            List<websiteStaticContentInfo> lstwebsiteStaticContent = new List<websiteStaticContentInfo>();
            SqlDataReader dr = null;
            try 
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteStaticContentSelectByFilters");
                setListwebsiteStaticContentInfo(ref dr, ref lstwebsiteStaticContent);
                return lstwebsiteStaticContent;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Insert websiteStaticContent
        /// </summary>
        /// <param name="websiteStaticContentInfo">Entity of websiteStaticContent</param>
        /// <returns>error code</returns>
        public static int Insert(websiteStaticContentInfo _websiteStaticContentInfo)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteStaticContentInsert"
                                            , _websiteStaticContentInfo.SataticContentID
											, _websiteStaticContentInfo.LanguageCode
											, _websiteStaticContentInfo.StaticContentCode
											, _websiteStaticContentInfo.StaticContent
											, _websiteStaticContentInfo.Description
											, _websiteStaticContentInfo.Atribute1
											, _websiteStaticContentInfo.Atribute2
											, _websiteStaticContentInfo.Atribute3
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        
        /// <summary>
        /// Update websiteStaticContent
        /// </summary>
        /// <param name="websiteStaticContentInfo">Entity of websiteStaticContent</param>
        /// <returns>error code</returns>
        public static int Update(websiteStaticContentInfo _websiteStaticContentInfo)
        {            
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteStaticContentUpdate"
											, _websiteStaticContentInfo.SataticContentID
											, _websiteStaticContentInfo.LanguageCode
											, _websiteStaticContentInfo.StaticContentCode
											, _websiteStaticContentInfo.StaticContent
											, _websiteStaticContentInfo.Description
											, _websiteStaticContentInfo.Atribute1
											, _websiteStaticContentInfo.Atribute2
											, _websiteStaticContentInfo.Atribute3
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Delete SchoolAdmin
        /// </summary>
        /// <param name="SataticContentID">Primary Key</param>
        /// <returns>error code</returns>
        public static int Delete(int SataticContentID)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteStaticContentDelete", SataticContentID);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        #endregion

        #region "Utilities method"
		
        private static void setListwebsiteStaticContentInfo(ref SqlDataReader dr, ref List<websiteStaticContentInfo> lstwebsiteStaticContent)
        {
            websiteStaticContentInfo _websiteStaticContentInfo = null;
            while (dr.Read())
            {
                _websiteStaticContentInfo = new websiteStaticContentInfo();
                setwebsiteStaticContentInfo(dr, ref _websiteStaticContentInfo);
                lstwebsiteStaticContent.Add(_websiteStaticContentInfo);
            }
        }

        private static void setwebsiteStaticContentInfo(SqlDataReader dr, ref websiteStaticContentInfo _websiteStaticContentInfo)
        {
			_websiteStaticContentInfo.SataticContentID = dr[websiteStaticContentDAL.FIELD_SATATICCONTENTID] != DBNull.Value ? Convert.ToInt32(dr[websiteStaticContentDAL.FIELD_SATATICCONTENTID]) : 0;
			_websiteStaticContentInfo.LanguageCode = dr[websiteStaticContentDAL.FIELD_LANGUAGECODE] != DBNull.Value ? Convert.ToString(dr[websiteStaticContentDAL.FIELD_LANGUAGECODE]) : string.Empty;
			_websiteStaticContentInfo.StaticContentCode = dr[websiteStaticContentDAL.FIELD_STATICCONTENTCODE] != DBNull.Value ? Convert.ToString(dr[websiteStaticContentDAL.FIELD_STATICCONTENTCODE]) : string.Empty;
			_websiteStaticContentInfo.StaticContent = dr[websiteStaticContentDAL.FIELD_STATICCONTENT] != DBNull.Value ? Convert.ToString((dr[websiteStaticContentDAL.FIELD_STATICCONTENT])) : null;
			_websiteStaticContentInfo.Description = dr[websiteStaticContentDAL.FIELD_DESCRIPTION] != DBNull.Value ? Convert.ToString(dr[websiteStaticContentDAL.FIELD_DESCRIPTION]) : string.Empty;
			_websiteStaticContentInfo.Atribute1 = dr[websiteStaticContentDAL.FIELD_ATRIBUTE1] != DBNull.Value ? Convert.ToString(dr[websiteStaticContentDAL.FIELD_ATRIBUTE1]) : string.Empty;
			_websiteStaticContentInfo.Atribute2 = dr[websiteStaticContentDAL.FIELD_ATRIBUTE2] != DBNull.Value ? Convert.ToString(dr[websiteStaticContentDAL.FIELD_ATRIBUTE2]) : string.Empty;
			_websiteStaticContentInfo.Atribute3 = dr[websiteStaticContentDAL.FIELD_ATRIBUTE3] != DBNull.Value ? Convert.ToString(dr[websiteStaticContentDAL.FIELD_ATRIBUTE3]) : string.Empty;
			                        
        }
        #endregion Methods

        #region Private Members

        private static string TABLE_NAME = "[mc_websiteStaticContent]";

        #endregion
    }
}

		